home *** CD-ROM | disk | FTP | other *** search
- char *strip(char *string, char *exclude, char mode) /* This strips a list of characters depending on mode */
- { /* Modifies the buffer directly */
- char *a;
- char *b;
- int match;
-
- switch(mode)
- {
- case 'S': /* strip at the start of the string */
- for(match=0,a=string; *a, !match; a++)
- {
- match=1;
- for(b=exclude; *b; b++)
- if (*a==*b)
- {
- strcpy(a, a+1);
- a--;
- match=0;
- }
- }
- break;
-
- case 'E': /* strip at the end of the string */
- for(match=0, a=string, a+=strlen(string)-1; *a, !match; a--)
- {
- match =1;
- for(b=exclude; *b && match; b++)
- {
- if (*a==*b)
- {
- strcpy(a, a+1);
- match=0;
- }
- }
- }
- break;
-
- case 'A': /* strip all from the string */
- for(a=string; *a; a++)
- {
- for(b=exclude; *b; b++)
- if(*a==*b)
- {
- strcpy(a, a+1);
- a--;
- }
- }
- break;
-
- case 'B': /* strip both beginning and end only */
- strip(string, exclude, 'S');
- strip(string, exclude, 'E');
- break;
-
- default:
- break;
- }
-
- return string;
- }
-